<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<script type="text/javascript">

// name space for this page
var p01_svcpkg = {
	mid: "${menuId}"
};

// for new item model
Ext.define('p01_svcpkg_itemModel',{
	extend:'Ext.data.Model',
	fields: [
        {name: 'spid',  type: 'string'},
        {name: 'name',   type: 'string'},
        {name: 'price_small', type: 'number'},
        {name: 'price_middle', type: 'number'},
        {name: 'price_big', type: 'number'},
        {name: 'price_high', type: 'number'},
        {name: 'description', type: 'string'},
        {name: 'status', type: 'string'},
        {name: 'status_disp_nm', type: 'string'}
    ]
}); 

// codition panel
p01_svcpkg.condPanel = Ext.create("Ext.form.Panel", {
	region: "north",
    buttonAlign: "left",
    frame: true,
    bodyPadding: 5,
    fieldDefaults: {
    	labelAlign: "left",
        labelWidth: 100,
        width: 240,
        labelStyle: "padding-left: 15px"
    },
    items: [{
        xtype: "fieldset",
    	title: "检索条件",
    	layout: "anchor",
        defaults: {
            padding: "2 0",
            anchor: "100%"
        },
        margin: "0",
    	items: [{
    	    xtype: "container",
            layout: "hbox",
            defaultType: "textfield",
            items: [{
            	id: "p01_svcpkg_name",
               	xtype: "textfield",
                fieldLabel: "套餐名称",
                name: "name"
            },  {
            	xtype: "uXcombo",
                name: "status",
                comboOpts: {
                    comboId: "CD0007",
                    hasBlank: true
                   // showType:'abbr'    abbr or full
                },
                fieldLabel: "状态",
                labelWidth: 80,
                width: 220,
                triggerAction: "all",
                forceSelection: true,
                editable: false,
               	value:'1'
            }]
        }, {
            xtype: "container",
            layout: "hbox",
            defaultType: "textfield",
            items: []
        }]
    }],
    buttons: [{
        text: "查询",
        id: "p01_svcpkg_search",
        handler: p01_svcpkg_storeLoad
    }, {
        text: "清空条件",
        handler: function() {
        	this.up("form").getForm().reset();
            Ext.getCmp("p01_svcpkg_name").focus();
        }
    },{
    	text: "添加",
        handler: p01_svcpkg_showAddItem
    }]
});

// 打开添加套餐tab页
function p01_svcpkg_showAddItem(){
	var id = p01_svcpkg.mid + 'addsvcpkg';
	var url = 'show_svcpkg.shtm?module=add';
	var title = '添加套餐';
	var optsStr = "{'id':'" + id + "', 'name': '" + title + "', 'url':'" + url + "'}";
	opts = Ext.decode(optsStr);
	crm.utils.createTopTab(opts);
}

//store
p01_svcpkg.store = Ext.create("Ext.data.Store", {
	model: p01_svcpkg_itemModel,
	proxy: {
	    type: "ajax",
	    url: "svcpkg/query.shtm",
	    actionMethods: {
	        read: "POST"
	    },
	    reader: {
	        root: "svcitems",
	        totalProperty: "totalCount"
	    },
	    simpleSortMode: true,
	    listeners: {
	        exception: function(proxy, resp, op, opts) {
	            var obj = Ext.JSON.decode(resp.responseText);
	            Ext.Msg.alert("信息提示", obj.errorMsgs);
	        }
	    }
	}
});

// grid panel
p01_svcpkg.gridPanel = Ext.create("Ext.grid.Panel", {
	region: "center",
	frame: true,
	margin:  0,
	autoScroll: true,
    store: p01_svcpkg.store,
    columns: [
        { text: "编号", width: 120,  dataIndex: "spid" },
        { text: "名称", width: 100, dataIndex: "name"},
        { text: "价格（小型车）", width: 150, dataIndex: "price_small"},
        { text: "价格（中型车）", width: 150, dataIndex: "price_middle"},
        { text: "价格（大型车）", width: 150, dataIndex: "price_big"},
        { text: "价格（高级车）", width: 150, dataIndex: "price_high"},
        { text: "状态", width: 80, dataIndex: "status_disp_nm"},
        { text: "服务说明", width: 150, dataIndex: "description"},
        {header: "操作", width: 80, xtype:'actioncolumn', items: [{
	        	icon: crm.global.basePath + 'images/icons/edit.png',
	        	// iconCls: 'p00_svcitemHand',
	        	altText:'编辑',
	        	handler: function(grid, rowIndex, colIndex){
	        		var rec = grid.getStore().getAt(rowIndex);
	        		var svc_item_id = rec.get('svc_item_id');
	        		p01_svcpkg_showItemWin(svc_item_id , 'edit');
	        	} 
        	},{
	        	icon: crm.global.basePath + 'images/icons/cross.gif',
	        	// iconCls: 'p00_svcitemHand',
	        	altText:'删除',
	        	handler: function(grid, rowIndex, colIndex){
	        		Ext.MessageBox.confirm('信息提示','确定删除？',function(id){
	        			if(id == 'no'){
		        			return;
	        			}
		        		var rec = grid.getStore().getAt(rowIndex);
		        		var spid = rec.get('spid');
		        		var p01_svcpkg_requestCon = {
		        			waitMsg: '删除中',
		        			url: 'svcpkg/delpkg.shtm',
		        			params: {spid: spid},
		        			callback: function(options, success, response){
		        				if(true == success){
		        					// Ext.Msg.alert("信息提示", "删除成功");
		        					p01_svcpkg_storeLoad();
		        				}else{
		        					Ext.Msg.alert('信息提示', "删除失败");
		        				}
		        				
		        			}
		        		};
		        		Ext.Ajax.request(p01_svcpkg_requestCon);
	        		});
	        	}
        	}]
        }
    ],
    viewConfig: {
    	forceFit: true
    }
});

// add to pTab
Ext.getCmp(p01_svcpkg.mid).add({
	xtype: "panel",
	bodyPadding: 0,
	border: 0,
	layout: "border",
	margin: 0,
	items: [p01_svcpkg.condPanel, p01_svcpkg.gridPanel]
});
//set "name" on focus.
Ext.getCmp("p01_svcpkg_name").focus();

p01_svcpkg_storeLoad();

// load the pkg store
function p01_svcpkg_storeLoad(){
	p01_svcpkg.store.loadPage({
    		params: p01_svcpkg.condPanel.getForm().getValues()
    });
}
</script>

